package com.ikas.ai.framework.node.impl;

import com.ikas.ai.framework.core.model.NodeInputVariables;
import com.ikas.ai.framework.flow.ScoreFlow;
import com.ikas.ai.framework.node.NodeType;

import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @Description: OR组合判断
 * @Author: qi.yilai
 * @Date: 2023/10/31 19:24
 * @Version: 1.0.0
 **/
public class OrPredictNode extends AbstractNode<Boolean> {

    public OrPredictNode(ScoreFlow scoreFlow, Long nodeId, Long nodeInstanceId, String name) {
        super(scoreFlow, nodeId, nodeInstanceId, name);
    }

    @Override
    public NodeType type() {
        return NodeType.OR_PREDICT;
    }

    @Override
    public NodeInputVariables outVariables() {
        NodeInputVariables nodeInputVariables = NodeInputVariables.copy(previous);
        nodeInputVariables.clearPredicts();
        mergeData(nodeInputVariables, result);
        return nodeInputVariables;
    }

    @Override
    Boolean doExecute() {
        AtomicBoolean r = new AtomicBoolean(false);
        List<Boolean> list = previous().getPredicts();
        list.stream().forEach(t -> {
            r.set(r.get() || t);
        });
        return r.get();
    }
}
